define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'wdsxh/activity_apply/index' + location.search,
                    add_url: 'wdsxh/activity_apply/add',
                    edit_url: 'wdsxh/activity_apply/edit',
                    del_url: 'wdsxh/activity_apply/del',
                    multi_url: 'wdsxh/activity_apply/multi',
                    import_url: 'wdsxh/activity_apply/import',
                    table: 'wdsxh_activity_apply',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('ID')},
                        {field: 'user.avatar', title: __('头像'),operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'user.nickname', title: __('昵称'),operate: false},
                        {field: 'member.name', title: __('会员姓名'),operate: false},
                        {field: 'member.mobile', title: __('会员电话'),operate: false},
                        {
                            field: 'userinfo',
                            title: __('报名信息'),
                            operate: false,
                            formatter: function (value, row, index) {
                                var html = '';
                                if(row.member == null) {
                                    html += "<p>姓名:"+row.name+"</p>";
                                    html += "<p>电话:"+row.mobile+"</p>";
                                    html += "<p>所属商会:"+row.chamber_of_commerce+"</p>";
                                    html += "<p>商会职务:"+row.chamber_of_commerce_position+"</p>";
                                    html += "<p>公司名称:"+row.company+"</p>";
                                    html += "<p>公司职务:"+row.company_position+"</p>";
                                }
                                return html;
                            }
                        },
                        {field: 'activity.title', title: __('活动标题'),operate: false},
                        {field: 'activity.time', title: __('活动时间'),operate: false},
                        // {field: 'money', title: __('Money'), operate:'BETWEEN'},
                        // {field: 'status', title: __('Status'), searchList: {"0":__('未支付'),"1":__('已支付'),"2":__('退款中'),"3":__('已退款'),"4":__('已完成')}, formatter: Table.api.formatter.status},
                        {field: 'status', title: __('Status'), searchList: {"0":__('Status 0'),"1":__('Status 1'),"4":__('Status 4')}, formatter: Table.api.formatter.status},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});